package com.gwz.cardserver.logic;

import com.gwz.cardserver.consts.FightCodeConst;
import com.gwz.cardserver.dto.ReqBase;
import com.gwz.cardserver.service.FightService;
import io.netty.channel.ChannelHandlerContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class FightHandler implements IHandler {
    @Autowired
    private FightService fightService;

    @Override
    public void channelRead(ChannelHandlerContext ctx, ReqBase reqBase) {
        switch (reqBase.getSubCode()) {
            /**
             * 抢地主
             */
            case FightCodeConst.GRAB_LANDLOAD: {
                // true 抢 false 不抢
                fightService.grabLandlord(ctx, reqBase);
                break;
            }
            case FightCodeConst.DEAL: {
                fightService.deal(ctx,reqBase);
                break;
            }
            case FightCodeConst.PASS:
            {
                fightService.pass(ctx, reqBase);
                break;
            }
        }
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) {

    }

    @Override
    public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
        fightService.handlerRemoved(ctx);
    }
}
